package net.infamily.dao.impl;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import net.infamily.dao.AbstractDao;

import com.google.inject.Inject;
import com.google.inject.Provider;

public abstract class AbstractDaoImpl<T> implements AbstractDao<T> {

	@Inject
	private Provider<PersistenceManager> persistenceManagerProvider;

	public PersistenceManager getPersistanceManager() {
		return persistenceManagerProvider.get();
	}
	
	public AbstractDaoImpl() {
		super();
	}

	@Override
	public Query createQuery(String queryString) {
		return getPersistanceManager().newQuery(queryString);
	}
	
	@Override
	public void persist(T object) {
		getPersistanceManager().makePersistent(object);
	}

	@Override
	public void remove(T object) {
		getPersistanceManager().deletePersistent(object);	
	}
	
	@Override
	public T find(Class<T> clazz, Object id) {
		return getPersistanceManager().getObjectById(clazz, id);
	}
}